<template>
  <div class="app-container">
    <!-- 功能区 -->
    <transition name="formFade">
      <el-card class="operate-container" shadow="never" v-if="showSearch">
        <el-form :inline="true" :model="listQuery" @submit.native.prevent>
          <el-form-item label="项目名称" class="form-item">
            <el-input v-model="listQuery.itemName" clearable class="filter-item" placeholder="项目名称"/>
          </el-form-item>
          <el-form-item label="采购类型:" class="form-item">
            <el-input v-model="listQuery.category" clearable class="filter-item" placeholder="采购类型"/>
          </el-form-item>
          <el-form-item label="是否需要招标:" class="form-item">
            <el-input v-model="listQuery.needBidding" clearable class="filter-item" placeholder="是否需要招标"/>
          </el-form-item>
          <el-form-item label="项目状态:" class="form-item">
            <el-input v-model="listQuery.status" clearable class="filter-item" placeholder="项目状态"/>
          </el-form-item>
          <el-form-item class="form-item">
            <el-button type="primary" size="mini" icon="el-icon-search" @click="getList">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </transition>
    <div class="table_content">
      <headerSearch :showAdd="false"
                    @creRefresh="getList"
                    @isSearch="showSearch = !showSearch"></headerSearch>
      <!--表格渲染-->
      <el-table ref="table" v-loading="loading" :data="list" border style="width: 100%;" border
                :header-cell-style="{background: '#F8F8F9', color: '#515a6e',padding: '6px 0 !important'}">
        <af-table-column prop="itemName" fixed="left" label="项目名称" />
        <el-table-column prop="category" label="采购类型">
          <template slot-scope="scope">
            {{{'0':'货物类', '1':'服务类'}[scope.row.category]}}
          </template>
        </el-table-column>
        <af-table-column prop="scale" label="规模分类" >
          <template slot-scope="scope">
            {{{'0':'10万以下','1':'15万以下','2':'10万-30万','3':'15万-30万','4':'30万以上'}[scope.row.scale]}}
          </template>
        </af-table-column>
        <af-table-column prop="purchaseType" label="采购方式" />
        <af-table-column prop="investment" label="金额(元)" />
        <el-table-column prop="needBidding" label="是否需要招标">
          <template slot-scope="scope">
            {{{'0':'不需要招标', '1':'需要招标'}[scope.row.needBidding]}}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="项目状态">
          <template slot-scope="scope">
            {{scope.row.status | statusFilters}}
          </template>
        </el-table-column>
        <af-table-column prop="buildUnit" label="采购单位" />
        <af-table-column prop="buildMan" label="采购单位负责人" />
        <el-table-column fixed="right" label="操作" min-width="80">
          <template slot-scope="scope">
            <el-button class="btn" type="text" size="small"
                       @click="seeEdit(scope.$index,scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <pagination v-show="total>0" :total="total"
                  :page.sync="listQuery.pageNum"
                  :limit.sync="listQuery.pageSize"
                  @pagination="getList" />
    </div>
  </div>
</template>

<script>
  import { doPost, doGet, doFile, orglistChild } from '@/api/index'
  import Pagination from '@/components/Pagination/index'
  import headerSearch from '@/components/headerSearch/headerSearch'

  export default {
    name: "purchasePro",
    components: {Pagination, headerSearch},
    data() {
      return {
        total: 0,
        listQuery: {
          pageNum: 1,
          pageSize: 20,
          status: '',
          needBidding: '',
          itemName: '',
          category: ''
        },
        list: [
          {
            itemName: '测试',
            category: 0,
            needBidding: 0,
            id: 1
          }
        ],
        loading: false,
        showSearch: true
      }
    },
    created() {
      // this.getList()
    },
    methods: {
      getList() {
        this.loading = true
        doPost('purchase/page', this.listQuery).then(res => {
          this.loading = false
          this.list = res.data.list
          this.total = res.data.total
        }).catch(error => {
          this.loading = false
          this.list = []
          this.total = 0
        })
      },
      //查看详情
      seeEdit(index, row) {
        this.$router.push({ name: 'productDetail', params: { id: row.id }})
      },
    },
    filters: {
      statusFilters(val) {
        return {
          '00': '立项',
          '01': '立项待审批',
          '02': '立项审批通过',
          '40': '开始招标',
          '41': '招标待审批',
          '42': '招标审批通过',
          '99': '项目归档',
        }[val]
      }
    }
  }
</script>

<style scoped>

</style>
